package io.shallwe._admin.line;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Ret;

import io.shallwe._admin.basedata.scanner.ScannerService;
import io.shallwe.common.controller.BaseController;
import io.shallwe.common.model.Account;
import io.shallwe.common.model.ExitBuffer;
import io.shallwe.common.model.Scanner;
import io.shallwe.front.ExitService;

import java.util.List;

/***
 *   出口下线扫描
* @author 王小伟
* @date 2019-06-10 21:17:33
*/
public class ExitScanController extends BaseController{
	
	@Inject
	ExitScanService service;
	
	@Inject ExitService exitService;

	@Inject
	ScannerService scannerService;
	
	public void index() {
		checkUrlPara(0);
		render("index.html");
	}
	
	public void list() {
		renderJson(exitService.paginate(1,100));
	}
	
	public void add() {
		render("add_edit.html");
	}
	
	@Before(ExitScanValidator.class)
	public void save() {
		ExitBuffer exitBuffer=getBean(ExitBuffer.class,"exitBuffer");
		Account loginAccount = getLoginAccount();
		renderJson(service.save(exitBuffer,loginAccount.getId()));
	}
	
	public void edit() {
		String id=get("id");
		ExitBuffer exitBuffer = service.findById(id);
		set("exitBuffer",exitBuffer);
		render("add_edit.html");
	}
	
	@Before(ExitScanValidator.class)
	public void update() {
		ExitBuffer exitBuffer=getBean(ExitBuffer.class,"exitBuffer");
		Account loginAccount = getLoginAccount();
		renderJson(service.update(exitBuffer,loginAccount.getId()));
	}
	
	
	public void print() {
		render("print.html");
	}
	
	public void delete() {
		String id=get("id");
		int type =getInt("type");
		renderJson(service.delete(id,type));
	}
	
	//人工扫描界面
	public void manualScanPage() {
		List<Scanner> scanners = scannerService.listManualExitScanner();
		set("scanners",scanners);
		render("manualScanPage.html");
	}
	
	//人工扫描操作
	public void manualScan() {
		String code=get("code");
		String ip=get("ip");
		Ret ret=service.scan(code,ip);
		renderJson(ret);
	}
	
	public void autoScanPage() {
		render("autoScanPage.html");
	}
	
	public void autoScan() {
		String hangNo=get("code");
		service.autoScan(hangNo);
		renderJson(Ret.ok("msg","操作成功"));
	}
}
